Example #1
0
bool
PngScreen::fileToImage (CompString &name,
			CompSize   &size,
			int        &stride,
			void       *&data)
{
    bool          status = false;
    std::ifstream file;
    CompString    fileName = fileNameWithExtension (name);

    file.open (fileName.c_str ());
    if (file.is_open ())
    {
	status = readPng (file, size, data);
	file.close ();
    }

    if (status)
    {
	stride = size.width () * 4;
	return true;
    }

    return screen->fileToImage (name, size, stride, data);
}
Example #2
0
bool
SvgScreen::fileToImage (CompString &path,
			CompSize   &size,
			int        &stride,
			void       *&data)
{
    CompString fileName = path;
    bool       status = false;
    int        len = fileName.length ();

    if (len < 4 || fileName.substr (len - 4, 4) != ".svg")
	fileName += ".svg";

    status = readSvgToImage (fileName.c_str (), size, data);

    if (status)
    {
	stride = size.width () * 4;
	return true;
    }

    status = screen->fileToImage (path, size, stride, data);

    return status;
}
Example #3
0
void
SvgWindow::setSvg (CompString    &data,
		   decor_point_t p[2])
{
    RsvgHandle *svg = NULL;
    GError     *error = NULL;

    if (!gWindow)
	return;

    svg = rsvg_handle_new_from_data ((guint8 *) data.c_str (),
				     data.length (), &error);

    if (source)
    {
	rsvg_handle_free (source->svg);
	source->svg = svg;
    }
    else
    {
	source = new SvgSource;
	if (source)
	    source->svg = svg;
    }

    if (source && source->svg)
    {
	source->p1 = p[0];
	source->p2 = p[1];

	source->svg = svg;

	gWindow->glDrawSetEnabled (this, true);
	rsvg_handle_get_dimensions (svg, &source->dimension);

	updateSvgContext ();
    }
    else
    {
	if (svg)
	    rsvg_handle_free (svg);

	if (source)
	{
	    delete source;
	    source = NULL;
	}

	if (context)
	{
	    finiTexture (context->texture[0]);
	    delete context;
	    context = NULL;
	}

	gWindow->glDrawSetEnabled (this, false);
    }
}
Example #4
0
CompString
PngScreen::fileNameWithExtension (CompString &path)
{
    unsigned int len = path.length ();

    if (len > 4 && path.substr (len - 4, 4) == ".png")
	return path;

    return path + ".png";
}
Example #5
0
void
NotificationScreen::logMessage (const char   *component,
			  	CompLogLevel level,
			  	const char   *message)
{
    NotifyNotification *n;
    char               *logLevel, *homeDir;
    CompString         iconUri;
    int                timeout;
    NotifyUrgency      urgency;

    if (level > optionGetMaxLogLevel ())
    {
	screen->logMessage (component, level, message);
	return;
    }

    homeDir = getenv ("HOME");
    if (!homeDir)
	return;

    /* FIXME: when not installing manually, the image will likely reside
              in $PREFIX/share/compiz, not in the home dir */
    iconUri   = "file://";
    iconUri += homeDir;
    iconUri += "/" IMAGE_DIR "/compiz.png";
    logLevel = (char *) logLevelToString (level);

    n = notify_notification_new (logLevel, message,
				 iconUri.c_str ()
#ifndef HAVE_LIBNOTIFY_0_6_1
				 , NULL
#endif				 
				 );

    timeout = optionGetTimeout ();
    if (timeout > 0)
	timeout *= 1000;

    notify_notification_set_timeout (n, timeout);

    if (level == CompLogLevelFatal || level == CompLogLevelError)
	urgency = NOTIFY_URGENCY_CRITICAL;
    else if (level == CompLogLevelWarn)
	urgency = NOTIFY_URGENCY_NORMAL;
    else
	urgency = NOTIFY_URGENCY_LOW;

    notify_notification_set_urgency (n, urgency);

    notify_notification_show (n, NULL);
    g_object_unref (G_OBJECT (n));

    screen->logMessage (component, level, message);
}
Example #6
0
/*
 * Left trimming function
 */
CompString
FragmentParser::ltrim (const CompString &string)
{
    size_t pos = 0;
    while (!(pos >= string.size ()))
    {
	if (isspace (string.at (pos)))
	    pos++;
	else
	    break;
    }

    return string.substr (pos);
}
Example #7
0
bool
CompText::renderWindowTitle (Window               window,
		             bool                 withViewportNumber,
		             const CompText::Attrib &attrib)
{
    CompString text;

    TEXT_SCREEN (screen);

    if (!ts)
	return false;

    if (withViewportNumber)
    {
	CompString title;
    	CompPoint  winViewport;
	CompSize   viewportSize;

	title = ts->getWindowName (window);
	if (!title.empty ())
	{
	    CompWindow *w;

	    w = screen->findWindow (window);
	    if (w)
	    {
		int viewport;

		winViewport  = w->defaultViewport ();
		viewportSize = screen->vpSize ();
		viewport = winViewport.y () * viewportSize.width () +
		           winViewport.x () + 1;
		text = compPrintf ("%s -[%d]-", title.c_str (), viewport);
	    }
	    else
	    {
		text = title;
	    }
	}
    }
    else
    {
	text = ts->getWindowName (window);
    }

    if (text.empty ())
	return false;

    return renderText (text, attrib);
}
Example #8
0
/*
 * Clean program name string
 */
void
FragmentParser::programCleanName (CompString &name)
{
    unsigned int pos = 0;

    /* Replace every non alphanumeric char by '_' */
    while (!(pos >= name.size ()))
    {
	if (!isalnum (name.at (pos)))
	    name[pos] = '_';

	pos++;
    }
}
Example #9
0
CompString
PrivateTextScreen::getWindowName (Window id)
{
    CompString name;

    name = getUtf8Property (id, visibleNameAtom);

    if (name.empty ())
	name = getUtf8Property (id, wmNameAtom);

    if (name.empty ())
	name = getTextProperty (id, XA_WM_NAME);

    return name;
}
CompString get_format (const CompString &fmt, Value::Ptr v)
{
    if (fmt == "%i" || fmt == "%d")
	return compPrintf(fmt.c_str(),
		(boost::shared_static_cast<TValue<int> >(v))->value());
    if (fmt == "%f")
	return compPrintf(fmt.c_str(),
		(boost::shared_static_cast<TValue<float> >(v))->value());
    if (fmt == "%s")
	return compPrintf(
		fmt.c_str(),
		(boost::shared_static_cast<TValue<std::string> >(v))->value().c_str());
    if (fmt == "%x")
	return compPrintf(fmt.c_str(),
		(boost::shared_static_cast<TValue<int> >(v))->value());

    return "not_reached";
}
Example #11
0
/*
 * File reader function
 */
CompString
FragmentParser::programReadSource (const CompString &fname)
{
    std::ifstream fp;
    int length;
    char *buffer;
    CompString data, path, home = CompString (getenv ("HOME"));

    /* Try to open file fname as is */
    fp.open (fname.c_str ());

    /* If failed, try as user filter file (in ~/.compiz/data/filters) */
    if (!fp.is_open () && !home.empty ())
    {
	path = home + "/.compiz/data/filters/" + fname;
	fp.open (path.c_str ());
    }

    /* If failed again, try as system wide data file
     * (in PREFIX/share/compiz/filters) */
    if (!fp.is_open ())
    {
	path = CompString (DATADIR) + "/data/filters/" + fname;
	fp.open (path.c_str ());
    }

    /* If failed again & again, abort */
    if (!fp.is_open ())
    {
	return CompString ("");
    }

    /* get length of file: */
    fp.seekg (0, std::ios::end);
    length = fp.tellg ();
    length++;
    fp.seekg (0, std::ios::beg);

    /* allocate memory */
    buffer = new char [length];

    /* read data as a block: */
    fp.read (buffer, length - 1);
    buffer[length - 1] = '\0';
    fp.close ();

    data = buffer;

    delete[] buffer;

    return data;
}
Example #12
0
bool
PngScreen::imageToFile (CompString &path,
			CompString &format,
			CompSize   &size,
			int	   stride,
			void	   *data)
{
    bool          status = false;
    std::ofstream file;
    CompString    fileName = fileNameWithExtension (path);

    if (format == "png")
    {
	file.open (fileName.c_str ());
	if (file.is_open ())
	{
	    status = writePng ((unsigned char *) data, file, size, stride);
	    file.close ();
	}

	if (status)
	    return true;
    }

    status = screen->imageToFile (path, format, size, stride, data);

    if (!status)
    {
	file.open (fileName.c_str ());
	if (file.is_open ())
	{
	    status = writePng ((unsigned char *) data, file, size, stride);
	    file.close ();
	}
    }

    return status;
}
Example #13
0
void
WSNamesScreen::renderNameText ()
{
    CompText::Attrib attrib;
    CompString	     name;

    textData.clear ();

    name = getCurrentWSName ();

    if (name.empty ())
        return;

    /* 75% of the output device as maximum width */
    attrib.maxWidth  = screen->getCurrentOutputExtents ().width () * 3 / 4;
    attrib.maxHeight = 100;

    attrib.family = "Sans";
    attrib.size = optionGetTextFontSize ();

    attrib.color[0] = optionGetFontColorRed ();
    attrib.color[1] = optionGetFontColorGreen ();
    attrib.color[2] = optionGetFontColorBlue ();
    attrib.color[3] = optionGetFontColorAlpha ();

    attrib.flags = CompText::WithBackground | CompText::Ellipsized;
    if (optionGetBoldText ())
        attrib.flags |= CompText::StyleBold;

    attrib.bgHMargin = 15;
    attrib.bgVMargin = 15;
    attrib.bgColor[0] = optionGetBackColorRed ();
    attrib.bgColor[1] = optionGetBackColorGreen ();
    attrib.bgColor[2] = optionGetBackColorBlue ();
    attrib.bgColor[3] = optionGetBackColorAlpha ();

    textData.renderText (name, attrib);
}
Example #14
0
static bool compileShader (GLuint *shader, GLenum type, CompString &source)
{
    const GLchar *data;
    GLint         status;

    data = (GLchar *)source.c_str ();

    *shader = (*GL::createShader) (type);
    (*GL::shaderSource) (*shader, 1, &data, NULL);
    (*GL::compileShader) (*shader);

    (*GL::getShaderiv) (*shader, GL::COMPILE_STATUS, &status);
    return (status == GL_TRUE);
}
Example #15
0
/*
 * Load a source file and build a Compiz Fragment Function from it
 */
GLFragment::FunctionId
FragmentParser::loadFragmentProgram (const CompString &file,
				     CompString &name,
				     int target)
{
    CompString source;
    GLFragment::FunctionId handle;

    /* Clean fragment program name */
    programCleanName (name);
    /* Read the source file */
    source = programReadSource (file);
    if (source.empty ())
    {
	return 0;
    }

    /* Build the Compiz Fragment Program */
    handle = buildFragmentProgram (source,
				   name, target);

    return handle;
}
Example #16
0
/*
 * Add a new fragment offset to the offsets stack from an ADD op string
 */
FragmentParser::FragmentOffset *
FragmentParser::programAddOffsetFromAddOp (const CompString &source)
{
    FragmentOffset  offset;
    CompString  op;
    size_t	    pos = 0;
    CompString	    name;
    CompString	    offsetString;
    CompString	    temp;
    std::list <FragmentOffset>::iterator it = offsets.begin ();

    if (source.size () < 5)
	return NULL;

    op = source;
    pos += 3;
    name = getFirstArgument (op, pos);
    if (name.empty ())
	return NULL;

    temp = getFirstArgument (op, pos);

    /* If an offset with the same name is
     * already registered, skip this one */
    if ((!offsets.empty () &&
	 !programFindOffset (it, name).empty ()) ||
	 temp.empty ())
	return &(*it);

    /* Just use the end of the op as the offset */
    pos += 1;
    offsetString = ltrim (op.substr (pos));
    if (offsetString.empty ())
	return NULL;

    offset.name =  name;
    offset.offset = offsetString;

    offsets.push_back (offset);

    return &(offsets.back ());
}
Example #17
0
/*
 * Build a Compiz Fragment Function from a source string
 */
GLFragment::FunctionId
FragmentParser::buildFragmentProgram (CompString &source,
				      const CompString &name,
				      int target)
{
    GLFragment::FunctionData *data;
    int handle;
    /* Create the function data */
    data = new GLFragment::FunctionData ();
    if (!data)
	return 0;
    /* Parse the source and fill the function data */
    programParseSource (data, target, source);
    /* Create the function */
    handle = data->createFragmentFunction (name.c_str ());
    delete data;
    return handle;
}
Example #18
0
bool
CompOption::stringToColor (CompString     color,
			   unsigned short *rgba)
{
    int c[4];

    if (sscanf (color.c_str (), "#%2x%2x%2x%2x",
		&c[0], &c[1], &c[2], &c[3]) == 4)
    {
	rgba[0] = c[0] << 8 | c[0];
	rgba[1] = c[1] << 8 | c[1];
	rgba[2] = c[2] << 8 | c[2];
	rgba[3] = c[3] << 8 | c[3];

	return true;
    }

    return false;
}
Example #19
0
int
BicubicScreen::getBicubicFragmentFunction (GLTexture   *texture,
					   int         param,
					   int         unit)
{
    GLFragment::FunctionData	*data;
    int				target;
    CompString			targetString;

    if (texture->target () == GL_TEXTURE_2D)
    {
	target	     = COMP_FETCH_TARGET_2D;
	targetString = "2D";
    }
    else
    {
	target	     = COMP_FETCH_TARGET_RECT;
	targetString = "RECT";
    }

    foreach (BicubicFunction *function, func)
	if (function->param  == param  &&
	    function->target == target &&
	    function->unit   == unit)
	    return function->handle;

    data = new GLFragment::FunctionData ();
    if (data)
    {
	int  handle = 0;
	BicubicFunction *function = NULL;

	CompString filterTemp[] = {
	    "hgX", "hgY", "cs00", "cs01", "cs10", "cs11"
	};

	for (unsigned int i = 0; i < sizeof (filterTemp) / sizeof (filterTemp[0]); i++)
	    data->addTempHeaderOp (filterTemp[i].c_str());


	data->addDataOp (
		"MAD cs00, fragment.texcoord[0], program.env[%d],"
		"{-0.5, -0.5, 0.0, 0.0};", param + 2);
	
	data->addDataOp ( 
		"TEX hgX, cs00.x, texture[%d], 1D;", unit);
	data->addDataOp ( 
		"TEX hgY, cs00.y, texture[%d], 1D;", unit);
	
	data->addDataOp (
		"MUL cs10, program.env[%d], hgX.y;", param);
	data->addDataOp (
		"MUL cs00, program.env[%d], -hgX.x;", param);
	data->addDataOp (
		"MAD cs11, program.env[%d], hgY.y, cs10;", param + 1);
	data->addDataOp (
		"MAD cs01, program.env[%d], hgY.y, cs00;", param + 1);
	data->addDataOp (
		"MAD cs10, program.env[%d], -hgY.x, cs10;", param + 1);
	data->addDataOp (
		"MAD cs00, program.env[%d], -hgY.x, cs00;", param + 1);

	data->addDataOp ( 
		"ADD cs00, cs00, fragment.texcoord[0];");
	data->addDataOp (
		"ADD cs01, cs01, fragment.texcoord[0];");
	data->addDataOp (
		"ADD cs10, cs10, fragment.texcoord[0];");
	data->addDataOp (
		"ADD cs11, cs11, fragment.texcoord[0];");

	data->addDataOp ( 
		"TEX cs00, cs00, texture[0], %s;", targetString.c_str());
	data->addDataOp (
		"TEX cs01, cs01, texture[0], %s;", targetString.c_str());
	data->addDataOp ( 
		"TEX cs10, cs10, texture[0], %s;", targetString.c_str());
	data->addDataOp ( 
		"TEX cs11, cs11, texture[0], %s;", targetString.c_str());

	data->addDataOp ( "LRP cs00, hgY.z, cs00, cs01;");
	data->addDataOp ( "LRP cs10, hgY.z, cs10, cs11;");
 
	data->addDataOp ( "LRP output, hgX.z, cs00, cs10;");
	
	data->addColorOp ( "output", "output");
	if (!data->status ())
	{
	    delete data;
	    return 0;
	}
	
	function = new BicubicFunction ();
	if (function)
	{
	    handle = data->createFragmentFunction ("bicubic");

	    function->handle = handle;
	    function->target = target;
	    function->param  = param;
	    function->unit   = unit;

	    func.push_back (function);
	}

	delete data;

	return handle;
    }

    return 0;
}
Example #20
0
/*
 * Get the first "argument" in the given string, trimmed
 * and move source string pointer after the end of the argument.
 * For instance in string " foo, bar" this function will return "foo".
 *
 * This function returns NULL if no argument found
 * or a malloc'ed string that will have to be freed later.
 */
CompString
FragmentParser::getFirstArgument (const CompString &line,
				  size_t &pos)
{
    CompString arg;
    CompString string;
    size_t next, temp, orig;
    int length;
    CompString retArg;

    if (pos >= line.size ())
	return CompString ("");

    /* Left trim */
    string = FragmentParser::ltrim (line.substr (pos));

    orig = pos;
    pos = 0;

    /* Find next comma or semicolon (which isn't that useful since we
     * are working on tokens delimited by semicolons) */
    if ((next = string.find (",", pos)) != std::string::npos ||
	(next = string.find (";", pos)) != std::string::npos)
    {
	length = next - pos;
	if (!length)
	{
	    pos = orig + 1;
	    return getFirstArgument (line, pos);
	}
	if ((temp = string.find ("{", pos) != std::string::npos) && temp < next &&
	    (temp = string.find ("}", pos) != std::string::npos) && temp > next)
	{
	    if ((next = string.find (",", temp)) != std::string::npos ||
		(next = string.find (";", temp)) != std::string::npos)
		length = next - pos;
	    else
		length = string.substr (pos).size ();
	}
    }
    else
	length = string.substr (pos).size ();

    /* Allocate, copy and end string */
    arg = string.substr (pos, length);

    /* Increment source pointer */
    if ((orig + arg.size () + 1) <= line.size ())
	pos += orig + arg.size () + 1;
    else
	pos = std::string::npos;

    return arg;
}
PropertyWriter::PropertyWriter (CompString propName,
				CompOption::Vector &readTemplate)
{
    mPropertyValues = readTemplate;
    mAtom = XInternAtom (screen->dpy (), propName.c_str (), 0);
}
Example #22
0
/*
 * Parse the source buffer op by op and add each op to function data
 *
 * FIXME : I am more than 200 lines long, I feel so heavy!
 */
void
FragmentParser::programParseSource (GLFragment::FunctionData *data,
		    		    int target, CompString &source)
{
    CompString line, next;
    CompString current;
    CompString strtok;
    size_t     pos = 0, strippos = 0;
    int   length, oplength, type;

    CompString arg1, arg2, temp;

    /* Find the header, skip it, and start parsing from there */

    pos = source.find ("!!ARBfp1.0", pos);
    if (pos != std::string::npos)
    {
	pos += 9;
    }

    /* Strip comments */
    while ((strippos = source.find ("#", strippos)) != std::string::npos)
    {
	size_t carriagepos = source.find ("\n", strippos);

	if (carriagepos != std::string::npos)
	{
	    source.erase (strippos, carriagepos - strippos);
	    strippos = 0;
	}
	else
	    source = source.substr (0, strippos);
    }

    strippos = 0;

    /* Strip linefeeds */
    while ((strippos = source.find ("\n", strippos)) != std::string::npos)
	source[strippos] = ' ';

    /* Parse each instruction */
    while (!(pos >= (source.size () - 1)))
    {
	size_t nPos = source.find (";", pos + 1);
	line = source.substr (pos + 1, nPos - pos);
	CompString origcurrent = current = ltrim (line);
	/* Find instruction type */
	type = NoOp;

	/* Data ops */
	if (current.substr (0, 3) == "END")
	    type = NoOp;
	else if (current.substr (0, 3) == "ABS" ||
		 current.substr (0, 3) == "CMP" ||
		 current.substr (0, 3) == "COS" ||
		 current.substr (0, 3) == "DP3" ||
		 current.substr (0, 3) == "DP4" ||
		 current.substr (0, 3) == "EX2" ||
		 current.substr (0, 3) == "FLR" ||
		 current.substr (0, 3) == "FRC" ||
		 current.substr (0, 3) == "KIL" ||
		 current.substr (0, 3) == "LG2" ||
		 current.substr (0, 3) == "LIT" ||
		 current.substr (0, 3) == "LRP" ||
		 current.substr (0, 3) == "MAD" ||
		 current.substr (0, 3) == "MAX" ||
		 current.substr (0, 3) == "MIN" ||
		 current.substr (0, 3) == "POW" ||
		 current.substr (0, 3) == "RCP" ||
		 current.substr (0, 3) == "RSQ" ||
		 current.substr (0, 3) == "SCS" ||
		 current.substr (0, 3) == "SIN" ||
		 current.substr (0, 3) == "SGE" ||
		 current.substr (0, 3) == "SLT" ||
		 current.substr (0, 3) == "SUB" ||
		 current.substr (0, 3) == "SWZ" ||
		 current.substr (0, 3) == "TXP" ||
		 current.substr (0, 3) == "TXB" ||
		 current.substr (0, 3) == "XPD")
		type = DataOp;
	else if (current.substr (0, 4) == "TEMP")
	    type = TempOp;
	else if (current.substr (0, 5) == "PARAM")
	    type = ParamOp;
	else if (current.substr (0, 6) == "ATTRIB")
	    type = AttribOp;
	else if (current.substr (0, 3) == "TEX")
	    type = FetchOp;
	else if (current.substr (0, 3) == "ADD")
	{
	    if (current.find ("fragment.texcoord", 0) != std::string::npos)
		programAddOffsetFromAddOp (current.c_str ());
	    else
		type = DataOp;
	}
	else if (current.substr (0, 3) == "MUL")
	{
	    if (current.find ("fragment.color", 0) != std::string::npos)
		type = ColorOp;
	    else
		type = DataOp;
	}
	else if (current.substr (0, 3) == "MOV")
	{
	    if (current.find ("result.color", 0) != std::string::npos)
		type = ColorOp;
	    else
		type = DataOp;
	}
	size_t cpos = 0;
	switch (type)
	{
	    /* Data op : just copy paste the
	     * whole instruction plus a ";" */
	    case DataOp:
		data->addDataOp (current.c_str ());
		break;
	    /* Parse arguments one by one */
	    case TempOp:
	    case AttribOp:
	    case ParamOp:
	    {
		if (type == TempOp) oplength = 4;
		else if (type == ParamOp) oplength = 5;
		else if (type == AttribOp) oplength = 6;
		length = current.size ();
		if (length < oplength + 2) break;

		cpos = oplength + 1;

		while (current.size () && !(cpos >= current.size ()) &&
		       (arg1 = getFirstArgument (current, cpos)).size ())
		{
		    /* "output" is a reserved word, skip it */
		    if (arg1.substr (0, 6) == "output")
			continue;
		    /* Add ops */
		    if (type == TempOp)
			data->addTempHeaderOp (arg1.c_str ());
		    else if (type == ParamOp)
			data->addParamHeaderOp (arg1.c_str ());
		    else if (type == AttribOp)
			data->addAttribHeaderOp (arg1.c_str ());
		}
	    }
		break;
	    case FetchOp:
	    {
		/* Example : TEX tmp, coord, texture[0], RECT;
		 * "tmp" is dest name, while "coord" is either
		 * fragment.texcoord[0] or an offset */
		cpos += 3;

		if ((arg1 = getFirstArgument (current, cpos)).size ())
		{
		    if (!(temp = getFirstArgument (current, cpos)).size ())
			break;

		    if (temp == "fragment.texcoord[0]")
			data->addFetchOp (arg1.c_str (), NULL, target);
		    else if (offsets.size ())
		    {
			arg2 = programFindOffset (
					      offsets.begin (),
					      temp);
			if (arg2.size ())
			    data->addFetchOp (arg1.c_str (),
					      arg2.c_str (), target);
		    }
		}
	    }
		break;
	    case ColorOp:
	    {
		if (current.substr (0, 3) == "MUL") /* MUL op, 2 ops */
		{
		    /* Example : MUL output, fragment.color, output;
		     * MOV arg1, fragment.color, arg2 */
		    cpos += 3;

		    if  (!(arg1 = getFirstArgument (current, cpos)).size ())
		    {
			break;
		    }

		    if (!(temp = getFirstArgument (current, cpos)).size ())
			break;

		    if (!(arg2 = getFirstArgument (current, cpos)).size ())
			break;

		    data->addColorOp (arg1.c_str (), arg2.c_str ());
		}
		else /* MOV op, 1 op */
		{
		    /* Example : MOV result.color, output;
		     * MOV result.color, arg1; */
		    cpos = current.find (",") + 1;

		    if ((arg1 = getFirstArgument (current, cpos)).size ())
			data->addColorOp ("output", arg1.c_str ());
		}
		break;
	    }
	    default:
		break;
	}
	pos = nPos;
    }
    programFreeOffset ();
}
Example #23
0
bool
TextSurface::render (const CompText::Attrib &attrib,
		     const CompString       &text)
{
    int width, height, layoutWidth;

    if (!valid ())
	return false;

    pango_font_description_set_family (font, attrib.family);
    pango_font_description_set_absolute_size (font,
					      attrib.size * PANGO_SCALE);
    pango_font_description_set_style (font, PANGO_STYLE_NORMAL);

    if (attrib.flags & CompText::StyleBold)
	pango_font_description_set_weight (font, PANGO_WEIGHT_BOLD);

    if (attrib.flags & CompText::StyleItalic)
	pango_font_description_set_style (font, PANGO_STYLE_ITALIC);

    pango_layout_set_font_description (layout, font);

    if (attrib.flags & CompText::Ellipsized)
	pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END);

    pango_layout_set_auto_dir (layout, false);
    pango_layout_set_text (layout, text.c_str (), -1);

    pango_layout_get_pixel_size (layout, &width, &height);

    if (attrib.flags & CompText::WithBackground)
    {
	width  += 2 * attrib.bgHMargin;
	height += 2 * attrib.bgVMargin;
    }

    width  = MIN (attrib.maxWidth, width);
    height = MIN (attrib.maxHeight, height);

    /* update the size of the pango layout */
    layoutWidth = attrib.maxWidth;
    if (attrib.flags & CompText::WithBackground)
	layoutWidth -= 2 * attrib.bgHMargin;

    pango_layout_set_width (layout, layoutWidth * PANGO_SCALE);

    if (!update (width, height))
	return false;

    pango_cairo_update_layout (cr, layout);

    cairo_save (cr);
    cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
    cairo_paint (cr);
    cairo_restore (cr);

    cairo_set_operator (cr, CAIRO_OPERATOR_OVER);

    if (attrib.flags & CompText::WithBackground)
    {
	drawBackground (0, 0, width, height,
			MIN (attrib.bgHMargin, attrib.bgVMargin));
	cairo_set_source_rgba (cr,
			       attrib.bgColor[0] / 65535.0,
			       attrib.bgColor[1] / 65535.0,
			       attrib.bgColor[2] / 65535.0,
			       attrib.bgColor[3] / 65535.0);
	cairo_fill (cr);
	cairo_move_to (cr, attrib.bgHMargin, attrib.bgVMargin);
    }

    cairo_set_source_rgba (cr,
			   attrib.color[0] / 65535.0,
			   attrib.color[1] / 65535.0,
			   attrib.color[2] / 65535.0,
			   attrib.color[3] / 65535.0);

    pango_cairo_show_layout (cr, layout);

    return true;
}
Example #24
0
static bool
dlloaderLoadPlugin (CompPlugin *p,
		    const char *path,
		    const char *name)
{
    CompString  file;
    void        *dlhand;
    bool        loaded = false;

    if (cloaderLoadPlugin (p, path, name))
	return true;

    if (path)
    {
	file  = path;
	file += "/";
    }

    file += "lib";
    file += name;
    file += ".so";

    compLogMessage (here, CompLogLevelDebug,
                    "Trying to load %s from: %s", name, file.c_str ());
    
    int open_flags = RTLD_NOW;
#ifdef DEBUG
    // Do not unload the library during dlclose.
    open_flags |= RTLD_NODELETE;
    // Make the symbols available globally
    open_flags |= RTLD_GLOBAL;
#endif
    dlhand = dlopen (file.c_str (), open_flags);
    if (dlhand)
    {
	PluginGetInfoProc getInfo;
	char		  *error;
	char              sym[1024];

	compLogMessage (here, CompLogLevelDebug,
	                "Opened library: %s", file.c_str ());
	dlerror ();

	snprintf (sym, 1024, "getCompPluginVTable20090315_%s", name);
	getInfo = (PluginGetInfoProc) dlsym (dlhand, sym);

	error = dlerror ();
	if (error)
	{
	    compLogMessage (here, CompLogLevelError, "dlsym: %s", error);
	    getInfo = 0;
	}

	if (getInfo)
	{
	    p->vTable = (*getInfo) ();
	    if (!p->vTable)
	    {
		compLogMessage (here, CompLogLevelError,
				"Couldn't get vtable from '%s' plugin",
				file.c_str ());
	    }
	    else
	    {
		p->devPrivate.ptr = dlhand;
		p->devType	  = "dlloader";
		loaded            = true;
		compLogMessage (here, CompLogLevelDebug,
		                "Loaded plugin %s from: %s",
		                name, file.c_str ());
	    }
	}
    }
    else
    {
	compLogMessage (here, CompLogLevelDebug,
			"dlopen failed: %s", dlerror ());
    }

    if (!loaded && dlhand)
	dlclose (dlhand);

    return loaded;
}