Пример #1
0
	void RotateUp(AVLNode* cur) {
		AVLNode* k = cur->parent;
		if (k == NULL) {
			return;
		}
		AVLNode* parent = k->parent;
		if (k->left == cur) {
			k->left = cur->right;
			if (k->left) {
				k->left->parent = k;
			}
			cur->right = k;
			k->parent = cur;
		} else {
			k->right = cur->left;
			if (k->right) {
				k->right->parent = k;
			}
			cur->left = k;
			k->parent = cur;
		}
		replaceChild(parent, k, cur);
		fixHeight(k);
		fixHeight(cur);
		fixHeight(parent);
		fixSize(k);
		fixSize(cur);
		fixSize(parent);
	}
Пример #2
0
void TupFramesTable::setItemSize(int w, int h)
{
    k->rectHeight = h;
    k->rectWidth = w;
    
    fixSize();
}
Пример #3
0
void TranslationLine::textChangedSlot()
{
	fixSize();
	if(isChanged())setStyleSheet("color: "+baseValues.appTheme.black.name());
	else setStyleSheet("color: "+baseValues.appTheme.red.name());
	emit lineTextChanged();
}
Пример #4
0
	void makeBalance(AVLNode* cur) {
		AVLNode* prev = NULL;
		while (cur != NULL) {
			fixHeight(cur);
			fixSize(cur);
			int leftHeight = getHeight(cur->left);	
			int rightHeight = getHeight(cur->right);
			if (leftHeight - rightHeight == 2) {
				int leftLeftHeight = getHeight(cur->left->left);
				int leftRightHeight = getHeight(cur->left->right);
				if (leftLeftHeight >= leftRightHeight) {
					cur = cur->left;
					RotateUp(cur);
				} else {
					cur = cur->left->right;
					RotateUp(cur);
					RotateUp(cur);
				}
			} else if (rightHeight - leftHeight == 2) {
				int rightLeftHeight = getHeight(cur->right->left);
				int rightRightHeight = getHeight(cur->right->right);
				if (rightRightHeight >= rightLeftHeight) {
					cur = cur->right;
					RotateUp(cur);
				} else {
					cur = cur->right->left;
					RotateUp(cur);
					RotateUp(cur);
				}
			}
			prev = cur;
			cur = cur->parent;
		}
		root_ = prev;
	}
Пример #5
0
void TranslationLine::setItemText(QString text)
{
	if(text.isEmpty())text=defaultText;
	text.replace("<br>","\n");
	setPlainText(text);
	document()->adjustSize();
	fixSize();
}
Пример #6
0
void Logger::log(unsigned int channel, const char * file, unsigned int line, const char * format, ...) {
	fixSize(channel);

	va_list l;
	va_start(l, format);
	channels[channel]->vprintf(format, l, file, line);
	va_end(l);
}
Пример #7
0
void TupFramesTable::insertLayer(int pos, const QString &name)
{
    Q_UNUSED(name);

    insertRow(pos);
    
    Private::LayerItem layer;
    layer.sound = false;
    k->layers.insert(pos, layer);
    
    fixSize();
}
Пример #8
0
void TupFramesTable::insertSoundLayer(int layerPos, const QString &name)
{
    Q_UNUSED(name);

    insertRow(layerPos);
    
    Private::LayerItem layer;
    layer.sound = true;
    k->layers.insert(layerPos, layer);
    
    fixSize();
}
Пример #9
0
Tree
mkBalTree (Tree t, Tree l, Tree r)
{
  int sizeL, sizeR, sizeT;
  sizeL = Tree_size(l);
  sizeR = Tree_size(r);
  sizeT = sizeL+sizeR+1;
  if (sizeL+sizeR < 2) {			/* only one subtree */
    t->left  = l;
    t->right = r;
    t->size  = sizeT;
    return t;
  } else if (sizeR > SIZE_RATIO*sizeL) {	/* right tree too big */
    if (Tree_size(r->left) < 2*Tree_size(r->right)) {
      /* transfer single branch L */
      t->left  = l;
      t->right = r->left;
      r->left  = fixSize(t);
      r->size  = sizeT;
      return r;
    } else {
      /* transfer double L branch of R to root */
      Tree rl;
      rl        = r->left;
      t->left   = l;
      t->right  = rl->left;
      r->left   = rl->right;
      rl->left  = fixSize(t);
      rl->right = fixSize(r);
      rl->size  = sizeT;
      return rl;
    }
  } else if (sizeL > SIZE_RATIO*sizeR) {	/* left tree too big */
    if (Tree_size(l->right) < 2*Tree_size(l->left)) {
      /* transfer single branch R */
      t->right = r;
      t->left  = l->right;
      l->right = fixSize(t);
      l->size  = sizeT;
      return l;
    } else {
      /* transfer double R branch of L to root */
      Tree lr;
      lr        = l->right;
      t->right  = r;
      t->left   = lr->right;
      l->right  = lr->left;
      lr->right = fixSize(t);
      lr->left  = fixSize(l);
      lr->size  = sizeT;
      return lr;
    }
  } else {					/* no imbalance */
    t->left  = l;
    t->right = r;
    t->size  = sizeT;
    return t;
  }
}
Пример #10
0
static void fixCoords(INT16* x, INT16* y, CARD16 *width, CARD16 *height)
{
	fixSize(width, height);

	if (!config.moveWindows)
		return;

	if (*width == config.mainW && *height == config.mainH)
	{
		*x = config.mainX;
		*y = config.mainY;
	}
}
Пример #11
0
void TupLayerIndex::insertSoundLayer(int position, const QString &name)
{
    if (position >= 0 && position <= rowCount()) {
        QTableWidgetItem *newLayer = new QTableWidgetItem(name);
        newLayer->setTextAlignment(Qt::AlignCenter);

        newLayer->setBackgroundColor(palette().background().color());
        newLayer->setTextColor(palette().foreground().color());

        insertRow(position);
        setItem(position, 0, newLayer);
        fixSize();
    }
}
Пример #12
0
void TCellView::addItem(TCellViewItem *item)
{
    if (columnCount() < MAX_COLUMNS)
        insertColumn(columnCount());

    if (m_countColor % MAX_COLUMNS == 0) {
        insertRow(rowCount());
        m_row++;
        m_col = 0;
    } else {
        m_col++;
    }

    m_countColor++;
    setItem(m_row-1 , m_col , item);

    fixSize();
}
Пример #13
0
bool KoToolDockMoveManager::check(int& x, int& y, int& w, int& h, bool change)
{

    int w1 = QMIN(QMAX(minSize.width(), w), maxSize.width());
    int h1 = QMIN(QMAX(minSize.height(), h), maxSize.height());

    bool f1 = (w1-w)+(h1-h) == 0;

    if (change) {
        if (mirrorX)
            x += w - w1;
        w = w1;
        if (mirrorY)
            y += h - h1;
        h = h1;
    }

    int x0 = x;
    int y0 = y;
    int w0 = w;
    int h0 = h;

    if (isDoMove)
        emit fixPosition(x0,y0,w0,h0);
    else
        emit fixSize(x0,y0,w0,h0);

    bool f2 = (x0==x)&&(y0==y)&&(w0==w)&&(h0==h);

    if (change) {
        x = x0;
        y = y0;
        w = w0;
        h = h0;
    }

    return f1&&f2;
}
Пример #14
0
void TupLayerIndex::resizeEvent(QResizeEvent *)
{
    fixSize();
}
Пример #15
0
void TCellView::setItemSize(int w, int h)
{
    m_rectHeight = h;
    m_rectWidth = w;
    QTimer::singleShot(0, this, SLOT(fixSize()));
}
Пример #16
0
void Logger::log(unsigned int channel, const char * file, unsigned int line, void (*callback)(const Logger& logger, const char * message)) {
	fixSize(channel);

	channels[channel]->setCallback(callback);
}
Пример #17
0
void Logger::log(unsigned int channel, const char * file, unsigned int line, unsigned int flag) {
	fixSize(channel);

	channels[channel]->setFlag(flag);
}
Пример #18
0
void Logger::log(unsigned int channel, const char * file, unsigned int line, std::ostream& os) {
	fixSize(channel);

	channels[channel]->setOutput(&os);
}
Пример #19
0
static void* x11connThreadWriteProc(void* dataPtr)
{
	X11ConnData* data = (X11ConnData*)dataPtr;

	unsigned char *buf = NULL;
	size_t bufLen = 0;

	{
		xConnSetupPrefix header;
		if (!recvAll(data->server, &header, sz_xConnSetupPrefix)) goto done;
		if (!sendAll(data->client, &header, sz_xConnSetupPrefix)) goto done;

		log_debug("Server connection setup reply: %d\n", header.success);

		size_t dataLength = header.length * 4;
		bufSize(&buf, &bufLen, dataLength);
		if (!recvAll(data->server, buf, dataLength)) goto done;
		if (!sendAll(data->client, buf, dataLength)) goto done;
	}

	bufSize(&buf, &bufLen, sz_xReply);
	while (!data->exiting)
	{
		if (!recvAll(data->server, buf, sz_xReply)) goto done;
		size_t ofs = sz_xReply;
		const xReply* reply = (xReply*)buf;

		if (reply->generic.type == X_Reply || reply->generic.type == GenericEvent)
		{
			size_t dataLength = reply->generic.length * 4;
			bufSize(&buf, &bufLen, ofs + dataLength);
			reply = (xReply*)buf; // in case bufSize moved buf
			if (!recvAll(data->server, buf+ofs, dataLength)) goto done;
			ofs += dataLength;
		}
		log_debug2(" [%d]Response: %d sequenceNumber=%d length=%d\n", data->index, reply->generic.type, reply->generic.sequenceNumber, ofs);

		if (reply->generic.type == X_Reply)
		{
			switch (data->notes[reply->generic.sequenceNumber])
			{
				case Note_X_GetGeometry:
				{
					xGetGeometryReply* reply = (xGetGeometryReply*)buf;
					log_debug2("  XGetGeometry(%d,%d,%d,%d)\n", reply->x, reply->y, reply->width, reply->height);
					fixCoords(&reply->x, &reply->y, &reply->width, &reply->height);
					log_debug2("  ->          (%d,%d,%d,%d)\n", reply->x, reply->y, reply->width, reply->height);
					break;
				}

				case Note_X_InternAtom_Other:
				{
					xInternAtomReply* reply = (xInternAtomReply*)buf;
					log_debug2("  X_InternAtom: atom=%d\n", reply->atom);
					break;
				}

				case Note_X_QueryExtension_XFree86_VidModeExtension:
				{
					xQueryExtensionReply* reply = (xQueryExtensionReply*)buf;
					log_debug2("  X_QueryExtension (XFree86-VidModeExtension): present=%d major_opcode=%d first_event=%d first_error=%d\n",
						reply->present, reply->major_opcode, reply->first_event, reply->first_error);
					if (reply->present)
						data->opcode_XFree86_VidModeExtension = reply->major_opcode;
					break;
				}

				case Note_X_QueryExtension_RANDR:
				{
					xQueryExtensionReply* reply = (xQueryExtensionReply*)buf;
					log_debug2("  X_QueryExtension (RANDR): present=%d major_opcode=%d first_event=%d first_error=%d\n",
						reply->present, reply->major_opcode, reply->first_event, reply->first_error);
					if (reply->present)
						data->opcode_RANDR = reply->major_opcode;
					break;
				}

				case Note_X_QueryExtension_Xinerama:
				{
					xQueryExtensionReply* reply = (xQueryExtensionReply*)buf;
					log_debug2("  X_QueryExtension (XINERAMA): present=%d major_opcode=%d first_event=%d first_error=%d\n",
						reply->present, reply->major_opcode, reply->first_event, reply->first_error);
					if (reply->present)
						data->opcode_Xinerama = reply->major_opcode;
					break;
				}

				case Note_X_QueryExtension_NV_GLX:
				{
					xQueryExtensionReply* reply = (xQueryExtensionReply*)buf;
					log_debug2("  X_QueryExtension (NV-GLX): present=%d major_opcode=%d first_event=%d first_error=%d\n",
						reply->present, reply->major_opcode, reply->first_event, reply->first_error);
					if (reply->present)
						data->opcode_NV_GLX = reply->major_opcode;
					break;
				}

				case Note_X_QueryExtension_Other:
				{
					xQueryExtensionReply* reply = (xQueryExtensionReply*)buf;
					log_debug2("  X_QueryExtension: present=%d major_opcode=%d first_event=%d first_error=%d\n",
						reply->present, reply->major_opcode, reply->first_event, reply->first_error);
					break;
				}

				case Note_X_XF86VidModeGetModeLine:
				{
					xXF86VidModeGetModeLineReply* reply = (xXF86VidModeGetModeLineReply*)buf;
					log_debug2("  X_XF86VidModeGetModeLine(%d x %d)\n", reply->hdisplay, reply->vdisplay);
					fixSize(&reply->hdisplay, &reply->vdisplay);
					log_debug2("  ->                      (%d x %d)\n", reply->hdisplay, reply->vdisplay);
					break;
				}

				case Note_X_XF86VidModeGetAllModeLines:
				{
					xXF86VidModeGetAllModeLinesReply* reply = (xXF86VidModeGetAllModeLinesReply*)buf;
					xXF86VidModeModeInfo* modeInfos = (xXF86VidModeModeInfo*)(buf + sz_xXF86VidModeGetAllModeLinesReply);
					for (size_t i=0; i<reply->modecount; i++)
					{
						xXF86VidModeModeInfo* modeInfo = modeInfos + i;
						log_debug2("  X_XF86VidModeGetAllModeLines[%d] = %d x %d\n", i, modeInfo->hdisplay, modeInfo->vdisplay);
						fixSize(&modeInfo->hdisplay, &modeInfo->vdisplay);
						log_debug2("  ->                                %d x %d\n",    modeInfo->hdisplay, modeInfo->vdisplay);
					}
					break;
				}

				case Note_X_RRGetScreenInfo:
				{
					xRRGetScreenInfoReply* reply = (xRRGetScreenInfoReply*)buf;
					xScreenSizes* sizes = (xScreenSizes*)(buf+sz_xRRGetScreenInfoReply);
					for (size_t i=0; i<reply->nSizes; i++)
					{
						xScreenSizes* size = sizes+i;
						log_debug2("  X_RRGetScreenInfo[%d] = %d x %d\n", i, size->widthInPixels, size->heightInPixels);
						fixSize(&size->widthInPixels, &size->heightInPixels);
						log_debug2("  ->                      %d x %d\n",    size->widthInPixels, size->heightInPixels);
					}
					break;
				}

				case Note_X_RRGetScreenResources:
				{
					xRRGetScreenResourcesReply* reply = (xRRGetScreenResourcesReply*)buf;
					void* ptr = buf+sz_xRRGetScreenResourcesReply;
					ptr += reply->nCrtcs * sizeof(CARD32);
					ptr += reply->nOutputs * sizeof(CARD32);
					for (size_t i=0; i<reply->nModes; i++)
					{
						xRRModeInfo* modeInfo = (xRRModeInfo*)ptr;
						log_debug2("  X_RRGetScreenResources[%d] = %d x %d\n", i, modeInfo->width, modeInfo->height);
						fixSize(&modeInfo->width, &modeInfo->height);
						log_debug2("  ->                           %d x %d\n",    modeInfo->width, modeInfo->height);
						ptr += sz_xRRModeInfo;
					}
					break;
				}

				case Note_X_RRGetCrtcInfo:
				{
					xRRGetCrtcInfoReply* reply = (xRRGetCrtcInfoReply*)buf;
					log_debug2("  X_RRGetCrtcInfo = %dx%d @ %dx%d\n", reply->width, reply->height, reply->x, reply->y);
					if (reply->mode != None)
					{
						fixMonitor(&reply->x, &reply->y, &reply->width, &reply->height);
						if (!reply->width || !reply->height)
						{
							reply->x = reply->y = reply->width = reply->height = 0;
							reply->mode = None;
							reply->rotation = reply->rotations = RR_Rotate_0;
							reply->nOutput = reply->nPossibleOutput = 0;
						}
					}
					log_debug2("  ->                %dx%d @ %dx%d\n", reply->width, reply->height, reply->x, reply->y);
					break;
				}

				case Note_X_XineramaQueryScreens:
				{
					xXineramaQueryScreensReply* reply = (xXineramaQueryScreensReply*)buf;
					xXineramaScreenInfo* screens = (xXineramaScreenInfo*)(buf+sz_XineramaQueryScreensReply);
					for (size_t i=0; i<reply->number; i++)
					{
						xXineramaScreenInfo* screen = screens+i;
						log_debug2("  X_XineramaQueryScreens[%d] = %dx%d @ %dx%d\n", i, screen->width, screen->height, screen->x_org, screen->y_org);
						fixCoords(&screen->x_org, &screen->y_org, &screen->width, &screen->height);
						log_debug2("  ->                           %dx%d @ %dx%d\n",    screen->width, screen->height, screen->x_org, screen->y_org);
					}
					break;
				}

				case Note_NV_GLX:
				{
#if 0
					char fn[256];
					static int counter = 0;
					sprintf(fn, "/tmp/hax11-NV-%d-rsp-%d", reply->generic.sequenceNumber, counter++);
					FILE* f = fopen(fn, "wb");
					fwrite(buf, 1, ofs, f);
					fclose(f);
#endif
					break;
				}
			}
		}

		if (config.debug >= 2 && config.actualX && config.actualY && memmem(buf, ofs, &config.actualX, 2) && memmem(buf, ofs, &config.actualY, 2))
			log_debug2("   Found actualW/H in output! ----------------------------------------------------------------------------------------------\n");

		if (!sendAll(data->client, buf, ofs)) goto done;
	}
done:
	log_debug("Exiting write thread.\n");
	data->exiting = 1;
	close(data->client);
	close(data->server);
	return NULL;
}
Пример #20
0
int main(int argc, char** argv)
{
  int i, j, count;
  FILE* f;

  char *prefix, *titleString, *temperature;

  int format; /* 0: PS  1: PNG  2: GIF  3: JPEG */
  int machine;

  char* buffer; /* for system() and fopen() */
  char* plotFile;

  /* functions to call - either PS or PNG */
  void (*init)();
  void (*title)(char*);
  void (*border)();
  void (*grid)();
  void (*plotDot)(int, int, double);
  void (*vertCenter)(char*, int);
  void (*horzCenter)(char*, int);
  void (*selection)(char*, int);

  g_filter = 0;
  g_grid = -1;
  g_dotSize = -1;
  g_top = g_left = g_size = -1;
  g_selectedI = g_selectedJ = -1;
  format = 0;
  machine = 0;
  titleString = NULL;
  g_cutoffValue = 0;
  getColor = getColorLogLog;
  g_epsilon = 0.01;
  temperature = "37";

  while ((count = getopt_long(argc, argv, "Vht:c:e:g:d:u:l:s:f:i:j:p:r:mo:", OPTIONS, NULL)) != -1)
    {
      if (count == 'V')
	version("hybrid-plot-ng");
      else if (count == 'h' || count == '?')
	{
	  puts("Usage: hybrid-plot-ng [options] <file prefix>");
	  puts("");
	  puts("Options:");
	  puts("-V, --version");
	  puts("-h, --help");
	  puts("-t, --temperature=<temperature>");
	  puts("-c, --colors=(linear | log | double) (defaults to double)");
	  puts("-e, --epsilon=<color epsilon> (defaults to .01)");
	  puts("-g, --grid=<grid spacing>");
	  puts("-d, --dot=<dot size>");
	  puts("-u, --top=<initial i>");
	  puts("-l, --left=<initial j>");
	  puts("-s, --size=<size of square>");
	  printf("-f, --format=(ps");
#if HAVE_GD_PNG
	  printf(" | png");
#endif
#if HAVE_GD_GIF
	  printf(" | gif");
#endif
#if HAVE_GD_JPEG
	  printf(" | jpeg");
#endif
	  puts(") (defaults to ps)");
	  puts("-i, --i=<selected i>");
	  puts("-j, --j=<selected j>");
	  puts("-p, --title=<plot title>");
	  puts("-r, --filter=(on | off) (defaults to off)");
	  puts("-o, --cutoff=<store cutoff>");
	  puts("");
	  puts("Report bugs to " PACKAGE_BUGREPORT);
	  return EXIT_SUCCESS;
	}
      else if (count == 't')
	temperature = optarg;
      else if (count == 'c')
	{
	  if (!strcmp(optarg, "linear"))
	    getColor = getColorLinear;
	  else if (!strcmp(optarg, "log"))
	    getColor = getColorLog;
	  else if (!strcmp(optarg, "double"))
	    getColor = getColorLogLog;
	}
      else if (count == 'e')
	g_epsilon = atof(optarg);
      else if (count == 'g')
	g_grid = atoi(optarg);
      else if (count == 'd')
	g_dotSize = atoi(optarg);
      else if (count == 'u')
	g_top = atoi(optarg);
      else if (count == 'l')
	g_left = atoi(optarg);
      else if (count == 's')
	g_size = atoi(optarg);
      else if (count == 'f')
	{
	  if (!strcmp(optarg, "ps"))
	    format = 0;
	  else if (!strcmp(optarg, "png"))
	    format = 1;
	  else if (!strcmp(optarg, "gif"))
	    format = 2;
	  else if (!strcmp(optarg, "jpeg"))
	    format = 3;
	}
      else if (count == 'i')
	g_selectedI = atoi(optarg);
      else if (count == 'j')
	g_selectedJ = atoi(optarg);
      else if (count == 'p')
	  {
	    titleString = xmalloc(strlen(optarg) + 1);
	    strcpy(titleString, optarg);
	  }
      else if (count == 'r')
	{
	  if (!strcmp(optarg, "on"))
	    g_filter = 1;
	  else if (!strcmp(optarg, "off"))
	    g_filter = 0;
	}
      else if (count == 'm')
	machine = 1;
      else if (count == 'o')
	g_cutoffValue = atof(optarg);
   }

  if (optind >= argc)
    {
      fputs("Error: no prefix specified\nRun 'hybrid-plot-ng -h' for help\n", stderr);
      return EXIT_FAILURE;
    }

  plotFile = xmalloc(strlen(argv[optind]) + 107);
  strcpy(plotFile, argv[optind]);

  for (i = 0; i <= strlen(argv[optind]); ++i)
    {
      if (argv[optind][i] == '-')
	{
	  g_ss = 0;
	  argv[optind][i] = 0;
	  break;
	}
      else if (argv[optind][i] == 0)
	{
	  g_ss = 1;
	  break;
	}
    }

  g_file1 = argv[optind];
  if (g_ss) /* from hybrid-ss */
    g_file2 = g_file1;
  else      /* from hybrid */
    g_file2 = argv[optind] + i + 1;

  if (g_ss)
    prefix = g_file1;
  else
    {
      prefix = xmalloc(strlen(g_file1) + 1 + strlen(g_file2) + 1);
      strcpy(prefix, g_file1);
      strcat(prefix, "-");
      strcat(prefix, g_file2);
    }

  if (!(f = fopen(g_file1, "rt")))
    {
      buffer = xmalloc(strlen(g_file1) + 5);
      strcpy(buffer, g_file1);
      strcat(buffer, ".seq");
      if (!(f = fopen(buffer, "rt")))
	{
	  perror(buffer);
	  return EXIT_FAILURE;
	}
      free(buffer);
    }
  input(f, &g_name1, &g_string1);
  fclose(f);
  if (!g_name1)
    g_name1 = g_file1;
  g_len1 = strlen(g_string1);

  if (g_ss)
    {
      g_name2 = g_name1;
      g_string2 = g_string1;
      g_len2 = g_len1;
    }
  else
    {
      if (!(f = fopen(g_file2, "rt")))
	{
	  buffer = xmalloc(strlen(g_file2) + 5);
	  strcpy(buffer, g_file2);
	  strcat(buffer, ".seq");
	  if (!(f = fopen(buffer, "rt")))
	    {
	      perror(buffer);
	      return EXIT_FAILURE;
	    }
	  free(buffer);
	}
      input(f, &g_name2, &g_string2);
      fclose(f);
      if (!g_name2)
	g_name2 = g_file2;;
      g_len2 = strlen(g_string2);
    }

  strcat(plotFile, ".");
  strcat(plotFile, temperature);
  strcat(plotFile, ".plot");

  if (!(f = fopen(plotFile, "rt")))
    {
      perror(plotFile);
      return EXIT_FAILURE;
    }
  g_scores = inputRecords(f);
  fclose(f);
  free(plotFile);

  if (!titleString)
    {
      titleString = xmalloc(1 + strlen(g_name1) + 7 + strlen(g_name2) + 5 + strlen(temperature) + 9);
      if (g_ss)
	sprintf(titleString, "'%s' at %s degrees", g_name1, temperature);
      else
	sprintf(titleString, "'%s' vs. '%s' at %s degrees", g_name1, g_name2, temperature);
    }

  if (g_top == -1 || g_left == -1 || g_size == -1)
    {
      g_top = g_left = 1;
      g_size = g_len1 > g_len2 ? g_len1 : g_len2;
      fixSize();
    }

  g_dotSpacing = (double) 484 / g_size;
  if (g_dotSize == -1)
    g_dotSize = roundInt(g_dotSpacing);
  if (g_dotSize < 1)
    g_dotSize = 1;
  if (g_grid < 0)
    {
      g_grid = g_size / 8;
      fixGrid();
    }
  if (g_grid)
    {
      g_labels = g_grid;
      fixLabels();
    }

  init = initPS;
  title = titlePS;
  border = borderPS;
  grid = gridPS;
  plotDot = plotDotPS;
  vertCenter = vertCenterPS;
  horzCenter = horzCenterPS;
  selection = selectionPS;
#if HAVE_GD
  if (format)
    {
      init = initPNG;
      title = titlePNG;
      border = borderPNG;
      grid = gridPNG;
      plotDot = plotDotPNG;
      vertCenter = vertCenterPNG;
      horzCenter = horzCenterPNG;
      selection = selectionPNG;
    }
#endif

  buffer = xmalloc(strlen(prefix) + 1 + strlen(temperature) + 5);
  strcpy(buffer, prefix);
  strcat(buffer, ".");
  strcat(buffer, temperature);
  if (format == 0)
    {
      strcat(buffer, ".ps");
      g_file = fopen(buffer, "wt");
    }
  else
    {
      if (format == 1)
	strcat(buffer, ".png");
      else if (format == 2)
	strcat(buffer, ".gif");
      else
	strcat(buffer, ".jpg");
      g_file = fopen(buffer, "wb");
#if HAVE_GD
      g_image = gdImageCreate(612, 612);
#endif
    }
  if (!g_file)
    {
      perror(buffer);
      return EXIT_FAILURE;
    }
  free(buffer);

  init();

  title(titleString);

  border();

  grid();

  for (i = 1; i <= g_len1; ++i)
    for (j = 1; j <= g_len2; ++j)
      if (g_scores[(i - 1) * g_len2 + j - 1] >= g_cutoffValue)
	if (g_filter == 0 || filter(i, j))
	  plotDot(i, j, g_scores[(i - 1) * g_len2 + j - 1]);

  if (g_selectedI > 0 && g_selectedJ > 0)
    {
      buffer = xmalloc(24);
      sprintf(buffer, "Selected: (%d-%c, %d-%c), %g",
	      g_selectedI, g_string1[g_selectedI - 1],
	      g_selectedJ, g_string2[g_selectedJ - 1],
	      g_scores[(g_selectedI - 1) * g_len2 + g_selectedJ - 1]);
      selection(buffer, g_gray);
    }

  if (format == 1)
#if HAVE_GD_PNG
    gdImagePng(g_image, g_file)
#endif
      ;
  else if (format == 2)
#if HAVE_GD_GIF
    gdImageGif(g_image, g_file)
#endif
      ;
  else if (format == 3)
#if HAVE_GD_JPEG
    gdImageJpeg(g_image, g_file, -1)
#endif
      ;

  fclose(g_file);

  if (machine)
    {
      /* save configuration */
      buffer = xmalloc(strlen(prefix) + 5);
      strcpy(buffer, prefix);
      strcat(buffer, ".cfg");
      if (!(f = fopen(buffer, "wt")))
	{
	  perror(buffer);
	  return EXIT_FAILURE;
	}
      free(buffer);
      fprintf(f, "%f\n", g_dotSpacing);
      fprintf(f, "%d\n", g_size);
      fclose(f);
    }

  return 0;
}
Пример #21
0
void TranslationLine::resizeEvent(QResizeEvent *event)
{
	QTextEdit::resizeEvent(event);
	fixSize();
}
Пример #22
0
static void* x11connThreadReadProc(void* dataPtr)
{
	X11ConnData* data = (X11ConnData*)dataPtr;
	unsigned char *buf = NULL;
	size_t bufLen = 0;
	bufSize(&buf, &bufLen, 1<<16);

	xConnClientPrefix header;
	if (!recvAll(data->client, &header, sizeof(header))) goto done;
	if (header.byteOrder != 'l')
	{
		log_debug("Unsupported byte order %c!\n", header.byteOrder);
		goto done;
	}
	if (!sendAll(data->server, &header, sz_xConnClientPrefix)) goto done;

	if (!recvAll(data->client, buf, pad(header.nbytesAuthProto))) goto done;
	if (!sendAll(data->server, buf, pad(header.nbytesAuthProto))) goto done;
	if (!recvAll(data->client, buf, pad(header.nbytesAuthString))) goto done;
	if (!sendAll(data->server, buf, pad(header.nbytesAuthString))) goto done;

	unsigned short sequenceNumber = 0;

	while (!data->exiting)
	{
		sequenceNumber++;

		size_t ofs = 0;
		if (!recvAll(data->client, buf+ofs, sz_xReq)) goto done;
		ofs += sz_xReq;

		const xReq* req = (xReq*)buf;
		uint requestLength = req->length * 4;
		if (requestLength == 0) // Big Requests Extension
		{
			recvAll(data->client, buf+ofs, 4);
			requestLength = *(uint*)(buf+ofs) * 4;
			ofs += 4;
		}
		log_debug2("[%d][%d] Request %d (%s) with data %d, length %d\n", data->index, sequenceNumber, req->reqType, requestNames[req->reqType], req->data, requestLength);
		bufSize(&buf, &bufLen, requestLength);
		req = (xReq*)buf; // in case bufSize moved buf

		if (!recvAll(data->client, buf+ofs, requestLength - ofs)) goto done;

		data->notes[sequenceNumber] = Note_None;
		switch (req->reqType)
		{
			// Fix for games that create the window of the wrong size or on the wrong monitor.
			case X_CreateWindow:
			{
				xCreateWindowReq* req = (xCreateWindowReq*)buf;
				log_debug2(" XCreateWindow(%dx%d @ %dx%d)\n", req->width, req->height, req->x, req->y);
				fixCoords(&req->x, &req->y, &req->width, &req->height);
				log_debug2(" ->           (%dx%d @ %dx%d)\n", req->width, req->height, req->x, req->y);
				break;
			}

			case X_ConfigureWindow:
			{
				xConfigureWindowReq* req = (xConfigureWindowReq*)buf;

				INT16 dummyXY = 0;
				CARD16 dummyW = config.mainW;
				CARD16 dummyH = config.mainH;
				INT16 *x = &dummyXY, *y = &dummyXY;
				CARD16 *w = &dummyW, *h = &dummyH;

				int* ptr = (int*)(buf + sz_xConfigureWindowReq);
				if (req->mask & 0x0001) // x
				{
					x = (INT16*)ptr;
					ptr++;
				}
				if (req->mask & 0x0002) // y
				{
					y = (INT16*)ptr;
					ptr++;
				}
				if (req->mask & 0x0004) // width
				{
					w = (CARD16*)ptr;
					ptr++;
				}
				if (req->mask & 0x0008) // height
				{
					h = (CARD16*)ptr;
					ptr++;
				}

				log_debug2(" XConfigureWindow(%dx%d @ %dx%d)\n", *w, *h, *x, *y);
				fixCoords(x, y, w, h);
				log_debug2(" ->              (%dx%d @ %dx%d)\n", *w, *h, *x, *y);
				break;
			}

			// Fix for games setting their window size based on the X root window size
			// (which can encompass multiple physical monitors).
			case X_GetGeometry:
			{
				data->notes[sequenceNumber] = Note_X_GetGeometry;
				break;
			}

			case X_InternAtom:
			{
				xInternAtomReq* req = (xInternAtomReq*)buf;
				const char* name = (const char*)(buf + sz_xInternAtomReq);
				log_debug2(" XInternAtom: %.*s\n", req->nbytes, name);
				data->notes[sequenceNumber] = Note_X_InternAtom_Other;
				break;
			}

			case X_ChangeProperty:
			{
				xChangePropertyReq* req = (xChangePropertyReq*)buf;
				log_debug2(" XChangeProperty: property=%d type=%d format=%d)\n", req->property, req->type, req->format);
				if (req->type == XA_WM_SIZE_HINTS)
				{
					XSizeHints* data = (XSizeHints*)(buf + sz_xChangePropertyReq);
					fixCoords((INT16*)&data->x, (INT16*)&data->y, (CARD16*)&data->width, (CARD16*)&data->height);
					fixSize((CARD16*)&data->max_width, (CARD16*)&data->max_height);
					fixSize((CARD16*)&data->base_width, (CARD16*)&data->base_height);
				}
				break;
			}

			case X_QueryExtension:
			{
				xQueryExtensionReq* req = (xQueryExtensionReq*)buf;
				const char* name = (const char*)(buf + sz_xQueryExtensionReq);
				log_debug2(" XQueryExtension(%.*s)\n", req->nbytes, name);

				if (!strmemcmp("XFree86-VidModeExtension", name, req->nbytes))
					data->notes[sequenceNumber] = Note_X_QueryExtension_XFree86_VidModeExtension;
				else
				if (!strmemcmp("RANDR", name, req->nbytes))
					data->notes[sequenceNumber] = Note_X_QueryExtension_RANDR;
				else
				if (!strmemcmp("XINERAMA", name, req->nbytes))
					data->notes[sequenceNumber] = Note_X_QueryExtension_Xinerama;
				else
				if (!strmemcmp("NV-GLX", name, req->nbytes))
					data->notes[sequenceNumber] = Note_X_QueryExtension_NV_GLX;
				else
					data->notes[sequenceNumber] = Note_X_QueryExtension_Other;
			}

			case 0:
				break;

			default:
			{
				if (req->reqType == data->opcode_XFree86_VidModeExtension)
				{
					xXF86VidModeGetModeLineReq* req = (xXF86VidModeGetModeLineReq*)buf;
					log_debug2(" XFree86_VidModeExtension - %d\n", req->xf86vidmodeReqType);
					switch (req->xf86vidmodeReqType)
					{
						case X_XF86VidModeGetModeLine:
							data->notes[sequenceNumber] = Note_X_XF86VidModeGetModeLine;
							break;
						case X_XF86VidModeGetAllModeLines:
							data->notes[sequenceNumber] = Note_X_XF86VidModeGetAllModeLines;
							break;
					}
				}
				else
				if (req->reqType == data->opcode_RANDR)
				{
					log_debug2(" RANDR - %d\n", req->data);
					switch (req->data)
					{
						case X_RRGetScreenInfo:
							data->notes[sequenceNumber] = Note_X_RRGetScreenInfo;
							break;
						case X_RRGetScreenResources:
							data->notes[sequenceNumber] = Note_X_RRGetScreenResources;
							break;
						case X_RRGetCrtcInfo:
							data->notes[sequenceNumber] = Note_X_RRGetCrtcInfo;
							break;
					}
				}
				else
				if (req->reqType == data->opcode_Xinerama)
				{
					log_debug2(" Xinerama - %d\n", req->data);
					switch (req->data)
					{
						case X_XineramaQueryScreens:
							data->notes[sequenceNumber] = Note_X_XineramaQueryScreens;
							break;
					}
				}
				else
				if (req->reqType == data->opcode_NV_GLX)
				{
#if 0
					char fn[256];
					sprintf(fn, "/tmp/hax11-NV-%d-req", sequenceNumber);
					FILE* f = fopen(fn, "wb");
					fwrite(buf, 1, requestLength, f);
					fclose(f);
#endif
					data->notes[sequenceNumber] = Note_NV_GLX;
				}
				break;
			}
		}

		if (config.debug >= 2 && config.actualX && config.actualY && memmem(buf, requestLength, &config.actualX, 2) && memmem(buf, requestLength, &config.actualY, 2))
			log_debug2("   Found actualW/H in input! ----------------------------------------------------------------------------------------------\n");

		if (!sendAll(data->server, buf, requestLength)) goto done;
	}
done:
	log_debug("Exiting read thread.\n");
	data->exiting = 1;
	close(data->client);
	close(data->server);
	return NULL;
}
Пример #23
0
void StatisticWindow::rebuild(QDate from, QDate to)
{
    QDateTime statStart(from);
    QDateTime statEnd(to.addDays(1));

    //prepare containers
    m_Uncategorized.TotalTime = 0;
    m_Uncategorized.NormalValue = 0;
    m_Uncategorized.Name = tr("Uncategorized");
    m_Uncategorized.Color = Qt::gray;
    m_Categories.resize(m_DataManager->categoriesCount());
    for (int i = 0; i<m_Categories.size(); i++){
        m_Categories[i].TotalTime = 0;
        m_Categories[i].NormalValue = 0;
        m_Categories[i].Name = m_DataManager->categories(i)->name;
        m_Categories[i].Color = m_DataManager->categories(i)->color;
    }

    m_Applications.resize(m_DataManager->applicationsCount());
    for (int i = 0; i<m_Applications.size(); i++){
        sAppInfo* app = m_DataManager->applications(i);
        m_Applications[i].TotalTime = 0;
        m_Applications[i].NormalValue = 0;
        m_Applications[i].Name = app->activities[0].name;
        m_Applications[i].Color = Qt::white;
        m_Applications[i].childs.resize(app->activities.size());
        for (int j = 0; j<m_Applications[i].childs.size(); j++){
            m_Applications[i].childs[j].TotalTime = 0;
            m_Applications[i].childs[j].NormalValue = 0;
            m_Applications[i].childs[j].Name = app->activities[j].name;
            m_Applications[i].childs[j].Color = Qt::white;
        }
    }

    //calculation
    int TotalTime = 0;
    for (int i = 0; i<m_Applications.size(); i++){
        const sAppInfo* app = m_DataManager->applications(i);
        for (int activity = 0; activity<app->activities.size(); activity++){
            const sActivityInfo* ainfo = &app->activities[activity];
            for (int j = 0; j<ainfo->periods.size(); j++){
                QDateTime start = ainfo->periods[j].start;
                QDateTime end = ainfo->periods[j].start.addSecs(ainfo->periods[j].length);
                if (end>statStart && start<statEnd){
                    if (start<statStart)
                        start = statStart;
                    if (end>statEnd)
                        end = statEnd;
                    int duration = start.secsTo(end);
                    TotalTime+=duration;
                    m_Applications[i].TotalTime+=duration;
                    m_Applications[i].childs[activity].TotalTime+=duration;
                    int cat = ainfo->categories[ainfo->periods[j].profileIndex].category;
                    if (cat==-1)
                        m_Uncategorized.TotalTime+=duration;
                    else
                        m_Categories[cat].TotalTime+=duration;
                }
                if (start>statEnd || end>statEnd)
                    break;
            }
        }
    }

    //calculate normalized values
    if (TotalTime>0){
        m_Uncategorized.NormalValue = (float)m_Uncategorized.TotalTime/TotalTime;
        for (int i = 0; i<m_Categories.size(); i++)
            m_Categories[i].NormalValue = (float)m_Categories[i].TotalTime/TotalTime;

        for (int i = 0; i<m_Applications.size(); i++){
            m_Applications[i].NormalValue = (float)m_Applications[i].TotalTime/TotalTime;
            for (int j = 0; j<m_Applications[i].childs.size(); j++)
                m_Applications[i].childs[j].NormalValue = (float)m_Applications[i].childs[j].TotalTime/TotalTime;
        }
    }

    qSort( m_Categories.begin(), m_Categories.end(), lessThan );

    ui->widgetDiagram->setTotalTime(TotalTime);
    ui->widgetDiagram->update();


    //fill applications widget
    ui->treeWidgetApplications->setSortingEnabled(false);
    ui->treeWidgetApplications->clear();
    for (int i = 0; i<m_Applications.size(); i++){
        if (m_Applications[i].TotalTime>0){
            QTreeWidgetItem* item = new QTreeWidgetItem();
            item->setText(0,m_Applications[i].Name);
            item->setData(0,Qt::UserRole,i);
            item->setText(1,DurationToString(m_Applications[i].TotalTime));
            item->setText(2,fixSize(QString::number(m_Applications[i].NormalValue*100,'f',2),5)+"%");
            ui->treeWidgetApplications->addTopLevelItem(item);
            for (int j = 0; j<m_Applications[i].childs.size(); j++){
                if (m_Applications[i].childs[j].TotalTime>0){
                    QTreeWidgetItem* aitem = new QTreeWidgetItem();
                    QString childName = m_Applications[i].childs[j].Name;
                    if (j==0)
                        childName+=tr("(default)");
                    aitem->setText(0,childName);
                    aitem->setData(0,Qt::UserRole,i);
                    aitem->setData(0,Qt::UserRole+1,j);
                    aitem->setText(1,DurationToString(m_Applications[i].childs[j].TotalTime));
                    aitem->setText(2,fixSize(QString::number(m_Applications[i].childs[j].NormalValue*100,'f',2),5)+"%");
                    item->addChild(aitem);
                }
            }

        }
    }
    ui->treeWidgetApplications->setSortingEnabled(true);
}