示例#1
0
FvwmPicture *GetPicture(Display *dpy,Window Root,char *IconPath,
		    char *PixmapPath, char *name, int color_limit)
{
  char *path;
  FvwmPicture *p;

  if(!(path=findIconFile(name,PixmapPath,R_OK)))
    if(!(path=findIconFile(name,IconPath,R_OK)))
      return NULL;
  p = LoadPicture(dpy,Root,path, color_limit);
  if (!p)
    free(path);
  return p;
}
示例#2
0
void LoadIcon(struct XObj *xobj)
{
 char *path = NULL;
 XWindowAttributes root_attr;
 XpmAttributes xpm_attributes;

 if ((xobj->icon)!=NULL)
 {
  path = (char*)findIconFile(xobj->icon, pixmapPath,4);
  if(path == NULL)return;  
  XGetWindowAttributes(xobj->display,RootWindow(xobj->display,DefaultScreen(xobj->display)),&root_attr);
  xpm_attributes.colormap = root_attr.colormap;
  xpm_attributes.valuemask = XpmSize | XpmReturnPixels|XpmColormap;
  if(XpmReadFileToPixmap(xobj->display, RootWindow(xobj->display,DefaultScreen(xobj->display)),
  			 path,
			 &xobj->iconPixmap,
			 &xobj->icon_maskPixmap, 
			 &xpm_attributes) == XpmSuccess) 
    { 
      xobj->icon_w = xpm_attributes.width;
      xobj->icon_h = xpm_attributes.height;
    } 
    else
    {
     fprintf(stderr,"Enable to load pixmap %s\n",xobj->icon);
     xobj->iconPixmap=None;
     xobj->icon_maskPixmap=None;
    }
  free(path);
 }
}
示例#3
0
void GoodyModuleSetIcon(struct MyInfo *mif, char *i)
{
  char *path;
#ifdef __DEBUG__
  fprintf(stderr, "FvwmTaskBar.GoodyModule.AddIcon(*,\"%s\")\n", i);
#endif
  if ((path=findIconFile(i,PixmapPath,R_OK)) ||
      (path=findIconFile(i,IconPath,R_OK))) {
    free(i);
    i = path;
  }

  if (mif == NULL) return;
  if (mif->icon != NULL) free(mif->icon);
  mif->icon = i;
}
示例#4
0
void GetXPMFile(char *file, char *path)
{
  char *full_file = NULL;

  view.attributes.valuemask = XpmReturnPixels| XpmCloseness | XpmExtensions;
  view.attributes.closeness = 40000 /* Allow for "similar" colors */;

  if (file)
    full_file = findIconFile(file,path,R_OK);

  if (full_file)
  {
    if(XpmReadFileToPixmap(dpy,
                           Root,
                           full_file,
                           &view.pixmap,
                           &view.mask,
                           &view.attributes) == XpmSuccess)
    {
      return;
    }
    fprintf(stderr,"FvwmBanner: ERROR reading pixmap file\n");
  }
  else
    fprintf(stderr,"FvwmBanner: ERROR finding pixmap file in PixmapPath\n");
  GetXPMData(fvwm2_big_xpm);
}
示例#5
0
FvwmPicture *CachePicture(Display *dpy,Window Root,char *IconPath,char *PixmapPath,
		      char *name, int color_limit)
{
  char *path;
  FvwmPicture *p=PictureList;

  /* First find the full pathname */
#ifdef XPM
  if(!(path=findIconFile(name,PixmapPath,R_OK)))
    if(!(path=findIconFile(name,IconPath,R_OK)))
      return NULL;
#else
  /* Ignore the given pixmap path when compiled without XPM support */
  if(!(path=findIconFile(name,IconPath,R_OK)))
    return NULL;
#endif

  /* See if the picture is already cached */
  while(p)
    {
      register char *p1, *p2;

      for (p1=path, p2=p->name; *p1 && *p2; ++p1, ++p2)
	if (*p1 != *p2)
          break;

      if(!*p1 && !*p2) /* We have found a picture with the wanted name */
	{
	  p->count++; /* Put another weight on the picture */
	  free(path);
	  return p;
	}
      p=p->next;
    }

  /* Not previously cached, have to load it ourself. Put it first in list */
  p=LoadPicture(dpy,Root,path, color_limit);
  if(p)
    {
      p->next=PictureList;
      PictureList=p;
    }
  else
    free(path);
  return p;
}
示例#6
0
void executeModule(XEvent * eventp, Window w, FvwmWindow * tmp_win,
		   unsigned long context, char *action, int *Module)
{
  int fvwm_to_app[2], app_to_fvwm[2];
  int i, val, nargs = 0;
  char *cptr;
  char *args[20];
  char *arg1 = NULL;
  char arg2[20];
  char arg3[20];
  char arg5[20];
  char arg6[20];
  extern char *ModulePath;
  extern char *fvwm_file;
  Window win;

  if (eventp->type != KeyPress)
    UngrabEm();

  if (action == NULL)
    return;

  if (tmp_win)
    win = tmp_win->w;
  else
    win = None;

  /* If we execute a module, don't wait for buttons to come up,
   * that way, a pop-up menu could be implemented */
  *Module = 0;

  action = GetNextToken(action, &cptr);

  arg1 = findIconFile(cptr, ModulePath, X_OK);
  if (arg1 == NULL) {
    if (cptr != NULL) {
      fvwm_msg(ERR, "executeModule",
	       "No such module %s%s", ModulePath, cptr);

      free(cptr);
    }
    return;
  }

  /* Look for an available pipe slot */
  for (i = 0; (i < npipes) && (writePipes[i] >= 0); ++i);

  if (i >= npipes) {
    fvwm_msg(ERR, "executeModule", "Too many Accessories!");
    if (cptr != NULL)
      free(cptr);
    return;
  }

  /* I want one-ended pipes, so I open two two-ended pipes,
   * and close one end of each. I need one ended pipes so that
   * I can detect when the module crashes/malfunctions */
  if (pipe(fvwm_to_app) != 0) {
    fvwm_msg(ERR, "executeModule", "Failed to open pipe");
    return;
  }
  if (pipe(app_to_fvwm) != 0) {
    fvwm_msg(ERR, "executeModule", "Failed to open pipe2");
    if (cptr != NULL)
      free(cptr);
    close(fvwm_to_app[0]);
    close(fvwm_to_app[1]);
    return;
  }

  pipeName[i] = stripcpy(cptr);
  sprintf(arg2, "%d", app_to_fvwm[1]);
  sprintf(arg3, "%d", fvwm_to_app[0]);
  sprintf(arg5, "%lx", (unsigned long) win);
  sprintf(arg6, "%lx", (unsigned long) context);
  args[0] = arg1;
  args[1] = arg2;
  args[2] = arg3;
  if (fvwm_file != NULL)
    args[3] = fvwm_file;
  else
    args[3] = "none";
  args[4] = arg5;
  args[5] = arg6;
  nargs = 6;
  while ((action != NULL) && (nargs < 20) && (strlen(args[nargs - 1]) > 0)) {
    args[nargs] = 0;
    action = GetNextToken(action, &args[nargs]);
    nargs++;
  }
  if (strlen(args[nargs - 1]) <= 0) {
    nargs--;
    if (args[nargs] != NULL)
      free(args[nargs]);
  }
  args[nargs] = 0;

  /* Try vfork instead of fork. The man page says that vfork is better! */
  /* Also, had to change exit to _exit() */
  /* Not everyone has vfork! */
  val = fork();
  if (val > 0) {
    /* This fork remains running fvwm */
    /* close appropriate descriptors from each pipe so
     * that fvwm will be able to tell when the app dies */
    close(app_to_fvwm[1]);
    close(fvwm_to_app[0]);

    /* add these pipes to fvwm's active pipe list */
    writePipes[i] = fvwm_to_app[1];
    readPipes[i] = app_to_fvwm[0];
    pipeOn[i] = -1;
    PipeMask[i] = MAX_MASK;
    free(arg1);
    pipeQueue[i] = NULL;

    /* make the PositiveWrite pipe non-blocking. Don't want to jam up
       fvwm because of an uncooperative module */
    fcntl(writePipes[i], F_SETFL, O_NDELAY);
    /* Mark the pipes close-on exec so other programs
     * won`t inherit them */
    if (fcntl(readPipes[i], F_SETFD, 1) == -1)
      fvwm_msg(ERR, "executeModule", "module close-on-exec failed");
    if (fcntl(writePipes[i], F_SETFD, 1) == -1)
      fvwm_msg(ERR, "executeModule", "module close-on-exec failed");
    for (i = 6; i < nargs; i++) {
      if (args[i] != 0)
	free(args[i]);
    }

    if (cptr != NULL)
      free(cptr);
  } else if (val == 0) {
    /* this is  the child */
    /* this fork execs the module */
    close(fvwm_to_app[1]);
    close(app_to_fvwm[0]);

    execvp(arg1, args);
    fvwm_msg(ERR, "executeModule", "Execution of module failed: %s", arg1);
    perror("");
    close(app_to_fvwm[1]);
    close(fvwm_to_app[0]);
    exit(1);
  } else {
    fvwm_msg(ERR, "executeModule", "Fork failed");
    free(arg1);
  }
  return;
}